﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace TransFormer.Web.admin
{
    public partial class Login : System.Web.UI.Page
    {
        private readonly TransFormer.BLL.UserInfo _bllUserInfo = new TransFormer.BLL.UserInfo();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {

            if (Regex.IsMatch(txtUserName.Text, @"^\w+$"))
            {
                if (Regex.IsMatch(txtPassword.Text, @"^\w+$"))
                {
                    string strWhere = string.Format("userName='{0}' and pwd='{1}'", txtUserName.Text, txtPassword.Text);

                    var list = _bllUserInfo.GetModelList(strWhere);
                    if (list == null || list.Count != 1)
                    {
                        loginResult.Text = "用户名或密码错误";
                        loginResult.ForeColor = Color.Red;

                    }
                    else
                    {
                        Session["userName"] = list.FirstOrDefault().Id;
                        Response.Redirect("main.aspx");
                    }
                }
            }


        }
    }
}